package com.halobits.thenumbergames.games;

import java.util.Random;

/**
 * Created by RAFAEL.SUENO on 1/14/2015.
 */
public class ClassicNumberGame implements NumberGame {
  protected int gridSize;
  protected int boardSize;
  protected int board[];
  protected int current;

  public ClassicNumberGame(int gridSize) {
    this.gridSize = gridSize;
    this.boardSize = gridSize*gridSize;
    this.board = new int[boardSize];
  }

  public void randomizeBoard() {
    resetBoard();
    for(int i = 1; i <= boardSize; i++) {
      Random rnd = new Random();
      int x;
      do {
        x = rnd.nextInt(boardSize);
      } while(board[x] != 0);
      board[x] = i;
    }
  }

  public void resetBoard() {
    for (int i = 0; i < boardSize; i++) {
      board[i] = 0;
    }
  }

  public void startGame() {
    current = 1;
  }

  public void resetGame() {
    randomizeBoard();
    current = 1;
  }

  public boolean doClick(int loc) {
    int l = loc;
    if(board[l] == current) {
      current++;
      return true;
    }
    return false;
  }

  public void setupGame() {
    randomizeBoard();
    current = 1;
  }

  public void stopGame() {

  }

  public int getGridSize() {
    return this.gridSize;
  }

  public int getBoardSize() {
    return this.boardSize;
  }

  public int[] getBoard() {
    return this.board;
  }

  public int getCurrent() {
    return this.current;
  }
}
